package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.Fitting2;

public class EdgeDetector2Wrapper extends Calculator {
	public static final String INPUT_X = "In X";
	public static final String INPUT_Y = "In Y";
	public static final String OUTPUT = "Output";
	
	public EdgeDetector2Wrapper() {
		initInput(INPUT_X);
		initInput(INPUT_Y);
		initOutput(OUTPUT);
	}
	
	@Override
	public void process() {
		Fitting2 fitting = new Fitting2("y=x(1) + x(2)*t");
		double[] y = null;
		if (this.getInput(INPUT_Y) != null) {
			y = this.getInput(INPUT_Y).getRealPart();
		}
		double[] x = null;
		if (this.getInput(INPUT_X) != null) {
			x = this.getInput(INPUT_X).getRealPart();
		}
		else {
			x = new double[y.length];
			for (int i = 0; i < y.length; i++) {
				x[i] = i;
			}
		}
		fitting.setOriginalData(x, y);
		int start = 0;
		for (int i = 1; i < x.length; i++) {
			double[] interpolatedX = new double[i - start];
			for (int j = 0; j < interpolatedX.length; j++) {
				interpolatedX[j] = x[start + j];
			}
			double[] iy = fitting.getInterpolated(interpolatedX);
			double slope = (iy[iy.length-1] - iy[0]) / (interpolatedX[interpolatedX.length-1]-interpolatedX[0]);
			
		}
	}

	@Override
	public Object getSetting() {
		// TODO Auto-generated method stub
		return null;
	}

}
